#pragma once
#include <vector>
#include "fmod.h"
#include "fmod.hpp"
#include "SoundTypes.h"

#define SOUNDMANAGER SoundManager::Instance()
#define INIT_VOLUME 0.5f

enum musicList {TITLE, MENU, BATTLE01, BATTLE02, WIN, LOSE} ;

enum soundList {
	MARCHING, 
	ARROW, 
	BUTTON,
	BATTLECRY,
	CLASH,
	VOICE_CHARGE,
	VOICE_ENGAGE,
	VOICE_FIRE,
	VOICE_RETREAT,
	VOICE_LOSE,
	VOICE_WIN,
	VOICE_YES,
	VOICE_NO,
	VOICE_RALLY,
	VOICE_REGROUP,
	VOICE_ENEMYCHARGE,
	VOICE_DIE01,
	VOICE_DIE02,
	VOICE_CHASE
} ;

struct SoundData
{
	FMOD::Sound*	sound;
	FMOD::Channel*	channel;
	unsigned int	id;
	float			vol;
};

struct MusicData
{
	FMOD::Sound*	stream;
	FMOD::Channel*	channel;
	unsigned int	id;
	float			vol;
	bool			m_Playing;
};

class SoundManager
{
private:
	// private constructors
	SoundManager(void);
	SoundManager(const SoundManager&);
	SoundManager* operator=(const SoundManager&);
	~SoundManager(void);

protected:
	typedef std::vector<SoundData*> Sounds;
	typedef std::vector<MusicData*> Musics;

	FMOD::System*		mSoundSystem;
	Sounds				mSoundList;
	Musics				mMusicList;

	float				mSoundVolume;
	float				mMusicVolume;

public:
	void Update();

	void LoadSound(char *filename, unsigned int soundID, float relativeVolume);
	void LoadMusic(char *filename, unsigned int musicID, float relativeVolume);

	void SoundPlay(unsigned int soundID);
	void SoundStop(unsigned int soundID);
	void SoundStop(void);

	void MusicPlay(unsigned int musicID);
	void MusicStop(unsigned int musicID);
	void MusicStop(void);

	void Initialize(void);

	void Release(void);

	void SetVolume(float soundVol, float musicVol);
	
	// accessing the singleton
	static SoundManager* Instance();
};